package com.brayan.melinxa.gui.panels;

import javax.swing.JPanel;
import java.awt.Color;
import javax.swing.BoxLayout;
import java.awt.FlowLayout;
import java.awt.GridBagLayout;
import java.awt.GridBagConstraints;
import java.awt.Insets;
import javax.swing.JToggleButton;
import javax.swing.JSeparator;
import javax.swing.JComboBox;
import javax.swing.JCheckBox;
import javax.swing.JTextPane;
import javax.swing.SwingConstants;
import javax.swing.JLabel;
import javax.swing.UIManager;
import java.util.ResourceBundle;
import javax.swing.JButton;

import com.brayan.melinxa.data.ApplicationSettings;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.Component;
import javax.swing.Box;

public class ApplicationSettingsPanel extends JPanel {

	private JCheckBox chckbxInvokeOnOsStartup;
	private JCheckBox chckbxActivateOnStartup;

	/**
	 * Create the panel.
	 */
	public ApplicationSettingsPanel() {
		setBackground(Color.WHITE);
		GridBagLayout gridBagLayout = new GridBagLayout();
		gridBagLayout.columnWidths = new int[] { 0, 10, 0, 0 };
		gridBagLayout.rowHeights = new int[] { 0, 0, 10, 0, 10, 0, 0, 0, 0 };
		gridBagLayout.columnWeights = new double[] { 0.0, 1.0, 0.0, Double.MIN_VALUE };
		gridBagLayout.rowWeights = new double[] { 0.0, 0.0, 1.0, 0.0, 1.0, 0.0, 1.0, 1.0,
				Double.MIN_VALUE };
		setLayout(gridBagLayout);
		
		Component verticalStrut = Box.createVerticalStrut(20);
		GridBagConstraints gbc_verticalStrut = new GridBagConstraints();
		gbc_verticalStrut.insets = new Insets(0, 0, 5, 5);
		gbc_verticalStrut.gridx = 1;
		gbc_verticalStrut.gridy = 0;
		add(verticalStrut, gbc_verticalStrut);
		
		Component horizontalStrut = Box.createHorizontalStrut(20);
		GridBagConstraints gbc_horizontalStrut = new GridBagConstraints();
		gbc_horizontalStrut.insets = new Insets(0, 0, 5, 5);
		gbc_horizontalStrut.gridx = 0;
		gbc_horizontalStrut.gridy = 1;
		add(horizontalStrut, gbc_horizontalStrut);

		JPanel panelLocalization = new JPanel();
		panelLocalization.setBackground(Color.WHITE);
		GridBagConstraints gbc_panelLocalization = new GridBagConstraints();
		gbc_panelLocalization.fill = GridBagConstraints.HORIZONTAL;
		gbc_panelLocalization.insets = new Insets(0, 0, 5, 5);
		gbc_panelLocalization.gridx = 1;
		gbc_panelLocalization.gridy = 1;
		add(panelLocalization, gbc_panelLocalization);
		GridBagLayout gbl_panelLocalization = new GridBagLayout();
		gbl_panelLocalization.columnWidths = new int[] { 54, 100, 0 };
		gbl_panelLocalization.rowHeights = new int[] { 22, 0, 0 };
		gbl_panelLocalization.columnWeights = new double[] { 0.0, 0.0, Double.MIN_VALUE };
		gbl_panelLocalization.rowWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
		panelLocalization.setLayout(gbl_panelLocalization);

		JComboBox comboBox = new JComboBox();
		GridBagConstraints gbc_comboBox = new GridBagConstraints();
		gbc_comboBox.anchor = GridBagConstraints.WEST;
		gbc_comboBox.insets = new Insets(0, 0, 5, 5);
		gbc_comboBox.gridx = 0;
		gbc_comboBox.gridy = 0;
		panelLocalization.add(comboBox, gbc_comboBox);

		JLabel lblLocalization = new JLabel(
				ResourceBundle
						.getBundle("locales.applicationSettings").getString("ApplicationSettings.lblLocalization.text")); //$NON-NLS-1$ //$NON-NLS-2$
		GridBagConstraints gbc_lblLocalization = new GridBagConstraints();
		gbc_lblLocalization.anchor = GridBagConstraints.WEST;
		gbc_lblLocalization.insets = new Insets(0, 0, 5, 0);
		gbc_lblLocalization.gridx = 1;
		gbc_lblLocalization.gridy = 0;
		panelLocalization.add(lblLocalization, gbc_lblLocalization);

		JTextPane textPnLocalizationDescription = new JTextPane();
		textPnLocalizationDescription.setEditable(false);
		GridBagConstraints gbc_textPnLocalizationDescription = new GridBagConstraints();
		gbc_textPnLocalizationDescription.anchor = GridBagConstraints.WEST;
		gbc_textPnLocalizationDescription.gridwidth = 2;
		gbc_textPnLocalizationDescription.gridx = 0;
		gbc_textPnLocalizationDescription.gridy = 1;
		panelLocalization.add(textPnLocalizationDescription, gbc_textPnLocalizationDescription);
		textPnLocalizationDescription
				.setText(ResourceBundle
						.getBundle("locales.applicationSettings").getString("ApplicationSettings.textPnLocalizationDescription.text")); //$NON-NLS-1$ //$NON-NLS-2$
		
		Component horizontalStrut_1 = Box.createHorizontalStrut(20);
		GridBagConstraints gbc_horizontalStrut_1 = new GridBagConstraints();
		gbc_horizontalStrut_1.insets = new Insets(0, 0, 5, 0);
		gbc_horizontalStrut_1.gridx = 2;
		gbc_horizontalStrut_1.gridy = 1;
		add(horizontalStrut_1, gbc_horizontalStrut_1);

		JPanel panel_4 = new JPanel();
		panel_4.setBackground(Color.WHITE);
		GridBagConstraints gbc_panel_4 = new GridBagConstraints();
		gbc_panel_4.anchor = GridBagConstraints.SOUTH;
		gbc_panel_4.insets = new Insets(0, 0, 5, 5);
		gbc_panel_4.fill = GridBagConstraints.HORIZONTAL;
		gbc_panel_4.gridx = 1;
		gbc_panel_4.gridy = 2;
		add(panel_4, gbc_panel_4);
		panel_4.setLayout(new BoxLayout(panel_4, BoxLayout.X_AXIS));

		JSeparator separator_1 = new JSeparator();
		panel_4.add(separator_1);

		JPanel panel = new JPanel();
		GridBagConstraints gbc_panel = new GridBagConstraints();
		gbc_panel.fill = GridBagConstraints.HORIZONTAL;
		gbc_panel.insets = new Insets(0, 0, 5, 5);
		gbc_panel.gridx = 1;
		gbc_panel.gridy = 3;
		add(panel, gbc_panel);
		panel.setBackground(Color.WHITE);
		GridBagLayout gbl_panel = new GridBagLayout();
		gbl_panel.columnWidths = new int[] { 185, 0 };
		gbl_panel.rowHeights = new int[] { 23, 0, 0 };
		gbl_panel.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
		gbl_panel.rowWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
		panel.setLayout(gbl_panel);

		chckbxInvokeOnOsStartup = new JCheckBox(ResourceBundle.getBundle("locales.applicationSettings").getString("ApplicationSettings.chckbxInvokeOnOsStartup.text")); //$NON-NLS-1$ //$NON-NLS-2$
		chckbxInvokeOnOsStartup.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//changedInvokeOnOsStartup();
			}
		});
		chckbxInvokeOnOsStartup.setBackground(Color.WHITE);
		GridBagConstraints gbc_chckbxInvokeOnOsStartup = new GridBagConstraints();
		gbc_chckbxInvokeOnOsStartup.insets = new Insets(0, 0, 5, 0);
		gbc_chckbxInvokeOnOsStartup.anchor = GridBagConstraints.NORTHWEST;
		gbc_chckbxInvokeOnOsStartup.gridx = 0;
		gbc_chckbxInvokeOnOsStartup.gridy = 0;
		panel.add(chckbxInvokeOnOsStartup, gbc_chckbxInvokeOnOsStartup);

		JTextPane textPnInvokeOnOsStartupDescription = new JTextPane();
		textPnInvokeOnOsStartupDescription.setEditable(false);
		textPnInvokeOnOsStartupDescription.setForeground(Color.BLACK);
		textPnInvokeOnOsStartupDescription
				.setText(ResourceBundle
						.getBundle("locales.applicationSettings").getString("ApplicationSettings.textPnInvokeOnOsStartupDescription.text")); //$NON-NLS-1$ //$NON-NLS-2$
		GridBagConstraints gbc_textPnInvokeOnOsStartupDescription = new GridBagConstraints();
		gbc_textPnInvokeOnOsStartupDescription.fill = GridBagConstraints.BOTH;
		gbc_textPnInvokeOnOsStartupDescription.gridx = 0;
		gbc_textPnInvokeOnOsStartupDescription.gridy = 1;
		panel.add(textPnInvokeOnOsStartupDescription, gbc_textPnInvokeOnOsStartupDescription);

		JPanel panel_3 = new JPanel();
		panel_3.setBackground(Color.WHITE);
		GridBagConstraints gbc_panel_3 = new GridBagConstraints();
		gbc_panel_3.anchor = GridBagConstraints.SOUTH;
		gbc_panel_3.insets = new Insets(0, 0, 5, 5);
		gbc_panel_3.fill = GridBagConstraints.HORIZONTAL;
		gbc_panel_3.gridx = 1;
		gbc_panel_3.gridy = 4;
		add(panel_3, gbc_panel_3);
		panel_3.setLayout(new BoxLayout(panel_3, BoxLayout.X_AXIS));

		JSeparator separator = new JSeparator();
		panel_3.add(separator);

		JPanel panel_1 = new JPanel();
		GridBagConstraints gbc_panel_1 = new GridBagConstraints();
		gbc_panel_1.fill = GridBagConstraints.HORIZONTAL;
		gbc_panel_1.insets = new Insets(0, 0, 5, 5);
		gbc_panel_1.gridx = 1;
		gbc_panel_1.gridy = 5;
		add(panel_1, gbc_panel_1);
		panel_1.setBackground(Color.WHITE);
		GridBagLayout gbl_panel_1 = new GridBagLayout();
		gbl_panel_1.columnWidths = new int[] { 348, 0 };
		gbl_panel_1.rowHeights = new int[] { 23, 20, 0 };
		gbl_panel_1.columnWeights = new double[] { 1.0, Double.MIN_VALUE };
		gbl_panel_1.rowWeights = new double[] { 0.0, 1.0, Double.MIN_VALUE };
		panel_1.setLayout(gbl_panel_1);

		chckbxActivateOnStartup = new JCheckBox(
				ResourceBundle
						.getBundle("locales.applicationSettings").getString("ApplicationSettings.chckbxActivateOnStartup.text"));
		chckbxActivateOnStartup.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				//changedActivateOnStartup();
			}
		});
		chckbxActivateOnStartup.setEnabled(false);
		chckbxActivateOnStartup.setHorizontalAlignment(SwingConstants.LEFT);
		chckbxActivateOnStartup.setBackground(Color.WHITE);
		GridBagConstraints gbc_chckbxActivateOnStartup = new GridBagConstraints();
		gbc_chckbxActivateOnStartup.anchor = GridBagConstraints.WEST;
		gbc_chckbxActivateOnStartup.insets = new Insets(0, 0, 5, 0);
		gbc_chckbxActivateOnStartup.gridx = 0;
		gbc_chckbxActivateOnStartup.gridy = 0;
		panel_1.add(chckbxActivateOnStartup, gbc_chckbxActivateOnStartup);

		JTextPane txtpnActivationOnAppStartupDescription = new JTextPane();
		txtpnActivationOnAppStartupDescription.setEnabled(false);
		txtpnActivationOnAppStartupDescription.setEditable(false);
		txtpnActivationOnAppStartupDescription
				.setText(ResourceBundle
						.getBundle("locales.applicationSettings").getString("ApplicationSettings.txtpnActivationOnAppStartupDescription.text")); //$NON-NLS-1$ //$NON-NLS-2$
		GridBagConstraints gbc_txtpnActivationOnAppStartupDescription = new GridBagConstraints();
		gbc_txtpnActivationOnAppStartupDescription.fill = GridBagConstraints.HORIZONTAL;
		gbc_txtpnActivationOnAppStartupDescription.gridx = 0;
		gbc_txtpnActivationOnAppStartupDescription.gridy = 1;
		panel_1.add(txtpnActivationOnAppStartupDescription,
				gbc_txtpnActivationOnAppStartupDescription);

		JPanel panel_5 = new JPanel();
		GridBagConstraints gbc_panel_5 = new GridBagConstraints();
		gbc_panel_5.anchor = GridBagConstraints.SOUTH;
		gbc_panel_5.insets = new Insets(0, 0, 5, 5);
		gbc_panel_5.fill = GridBagConstraints.HORIZONTAL;
		gbc_panel_5.gridx = 1;
		gbc_panel_5.gridy = 6;
		add(panel_5, gbc_panel_5);
		panel_5.setLayout(new BoxLayout(panel_5, BoxLayout.X_AXIS));

		JSeparator separator_2 = new JSeparator();
		panel_5.add(separator_2);

		JPanel panel_2 = new JPanel();
		panel_2.setBackground(Color.WHITE);
		FlowLayout flowLayout = (FlowLayout) panel_2.getLayout();
		flowLayout.setAlignment(FlowLayout.RIGHT);
		GridBagConstraints gbc_panel_2 = new GridBagConstraints();
		gbc_panel_2.insets = new Insets(0, 0, 0, 5);
		gbc_panel_2.fill = GridBagConstraints.BOTH;
		gbc_panel_2.gridx = 1;
		gbc_panel_2.gridy = 7;
		add(panel_2, gbc_panel_2);

		JButton btnSave = new JButton(
				ResourceBundle
						.getBundle("locales.applicationSettings").getString("ApplicationSettings.btnNewButton_1.text")); //$NON-NLS-1$ //$NON-NLS-2$
		btnSave.addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent e) {
				changedActivateOnStartup();
				changedInvokeOnOsStartup();
			}
		});
		panel_2.add(btnSave);

	}

	protected void changedActivateOnStartup() {
		ApplicationSettings.setActivateOnStartup(chckbxActivateOnStartup.isSelected());		
	}

	protected void changedInvokeOnOsStartup() {
		ApplicationSettings.setInvokeOnOsStartup(chckbxInvokeOnOsStartup.isSelected());
	}
}
